import { _decorator, Component, Node, Sprite, SpriteFrame, v4 } from "cc";
const { ccclass, property } = _decorator;

@ccclass("CdItemScript")
export class CdItemScript extends Component {

    protected start(): void {
        let sf:SpriteFrame = this.getComponent(Sprite).spriteFrame ;
        console.log(sf.uv)
        let l = sf.uv[0];
        let r = sf.uv[6];
        let b = sf.uv[3];
        let t = sf.uv[5];
        let u_uvOffset = v4(l, t, r, b);
        let u_uvRotated = sf.rotated ? 1 : 0;
        //
        this.getComponent(Sprite).material.setProperty("u_uvOffset", u_uvOffset);
        this.getComponent(Sprite).material.setProperty("u_uvRotated", u_uvRotated);
    }

    private _cd: number = 3;
    private _totalTime: number = 0;

    protected update(dt: number): void {
        this._totalTime += dt;
        if (this._totalTime > this._cd) {
            this._totalTime = this._totalTime % this._cd;
        }
        // console.log(this._totalTime )
        this.percent = (this._totalTime / this._cd);
    }

    public set cd(value: number) {
        this._cd = value;
    }

    public set percent(value: number) {
        this.getComponent(Sprite).material.setProperty("progressValue", value);
    }
}
